import {Component, OnInit} from "@angular/core";
import {Page} from "../../../public/util/page";
import {UserService} from "../user.service";
import {Enums, States, UserDepositStates} from '../../../public/setting/enums';
import {SettingUrl} from "../../../public/setting/setting_url";

@Component({
  selector: 'app-user-deposit-list',
  templateUrl: './user-deposit-list.component.html',
  styleUrls: ['./user-deposit-list.component.scss']
})
export class UserDepositListComponent implements OnInit {
  public searchParams: any = {};//搜索参数
  public userDepositList: Page = new Page(); //供应商
  public _loading: boolean = false;
  public routerLinks = SettingUrl.ROUTERLINK;//路由
  public userDepositState = Enums.userDepositState;       // 状态
  public userDepositStates = UserDepositStates;

  constructor(private userService: UserService) {
  }

  ngOnInit() {
    this.queryUserDepositList()
  }

  /**
   * 查询userDeposit列表
   * @param curPage 当前页
   */
  queryUserDepositList(curPage?: number) {
    this._loading = true;
    if (curPage) this.userDepositList.curPage = curPage;//当有页码时，查询该页数据
    this.userDepositList.params = {
      account: this.searchParams.account, //account
      curPage: this.userDepositList.curPage, //目标页码
      pageSize: this.userDepositList.pageSize, //每页条数
    };
    this.userService.getUserDepositList(this.userDepositList.params).then((res: Page) => {
      this._loading = false;
      this.userDepositList = res;
    }).catch(err => {
      this._loading = false;
    })
  }

  /**
   * 重置搜索
   */
  resetSearch() {
    this.searchParams = {};
    this.queryUserDepositList(1)
  }
}
